package com.atguigu.gmall.activity.service.impl;

import com.atguigu.gmall.activity.mapper.ActivityInfoMapper;
import com.atguigu.gmall.activity.service.ActivityInfoService;
import com.atguigu.gmall.model.activity.ActivityInfo;
import com.atguigu.gmall.model.activity.ActivityRuleVo;
import com.atguigu.gmall.model.activity.enums.ActivityInfoEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: zm
 * @Date: 2021/8/10 22:14
 */
@Service
public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper,ActivityInfo> implements ActivityInfoService {



    // 获取活动列表 分页
    @Override
    public IPage getActivityInfoList(Page<ActivityInfo> activityInfoPage) {
        QueryWrapper<ActivityInfo> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        Page<ActivityInfo> page = baseMapper.selectPage(activityInfoPage, wrapper);
        List<ActivityInfo> records = page.getRecords();

        records.stream().forEach(info->{
            info.setActivityTypeString(ActivityInfoEnum.valueOf(info.getActivityType()).getActivityName());
        });

/*        for (ActivityInfo info : records) {
            if("FULL_REDUCTION".equalsIgnoreCase(info.getActivityType())){
                info.setActivityTypeString("满减");
            }else if("FULL_DISCOUNT".equalsIgnoreCase(info.getActivityType())){
                info.setActivityTypeString("满量打折");
            }
        }*/

        return page;
    }
}
